<?php
/* @var $this RechargeController */
/* @var $model Recharge */
/* @var $form CActiveForm */
/* 3G 客户充值页面*/
?>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'agent-recharge-form',
	'enableAjaxValidation'=>false,
));
$Deduct = Yii::t('base', 'Deduct from Deposit'); //押金付款
$choose = Yii::t('base', 'Please Choose'); //请您选择
$Credit = Yii::t('base','Credit Card');   //信用卡
$Bank = Yii::t('base','Direct Debit'); //银行卡
$cash = Yii::t('base','cash');  //现金
$transfer = Yii::t('base','bank transfer'); //银行转账
//查询当前用户是否绑定信用卡信息
$sql="select * from zy_card_info where user_id='".yii::app()->user->id."'";
$cardInfo=Yii::app()->db->createCommand($sql)->queryAll();
if(empty($cardInfo)){
	$cardInfoSize = 0;
}else{
	$cardInfoSize = 1;
}

$defaultpay = CardInfo::model()->checkboxValid();
if(empty($defaultpay)){
    $defaultpay=0;
}

Yii::app()->clientScript->registerScript('admin', "
$(document).ready(function(){
        var tag = $('#tag').val();
		$('#AgentRecharge_package_id').append('<option value=0>'+'$choose'+'</option>');
		$('#AgentRecharge_package_id option[value=0] ').attr('selected',true);
		$('#AgentRecharge_recharge_number').empty();
		$('#AgentRecharge_recharge_number').hide();
		$('#vista').hide();
		$('#card-info-grid').hide();
		$('#prompt').hide();
                 if(tag == 1){
                    $('label:eq(2)').hide();
                }else{
                    $('label:eq(1)').hide();
                }
		$('#AgentRecharge_recharge_type').empty();
		$('#AgentRecharge_recharge_type').hide();
                if(tag == 1){
                    $('label:eq(3)').hide();
                }else{
                    $('label:eq(2)').hide();
                }
		$('#AgentRecharge_package_id').change(function(){
			$('#AgentRecharge_recharge_number').empty();
			$('#AgentRecharge_recharge_number').hide();
			 if(tag == 1){
                            $('label:eq(2)').hide();
                        }else{
                            $('label:eq(1)').hide();
                        }
			$('#AgentRecharge_recharge_type').empty();
			$('#AgentRecharge_recharge_type').hide();
			if(tag == 1){
                            $('label:eq(3)').hide();
                        }else{
                            $('label:eq(2)').hide();
                        }
			var internet_traffic = $(this).val();
			var options = $('#AgentRecharge_package_id option:selected').text();AgentRecharge_package_id
			for(var i=0;i<b.length;i++){
				if(internet_traffic==b[i][0]){
					$('#AgentRecharge_recharge_number').append('<option>'+b[i][1]+'</option>');
					$('#AgentRecharge_recharge_number').show();
					$('label:eq(1)').show();
                                        if(tag == 1){
                                             $('label:eq(3)').show();
                                        }
				}
			}
        if(tag != 1){
				var option = options.substring(0,3);
				if(option=='1GB'){	//选择1GB套餐触发事件
						$('#card-info-grid').hide();
						$('#vista').hide();
						$('#prompt').hide();
						$('#AgentRecharge_recharge_type').append('<option value=3>'+'$Deduct'+'</option>');
						$('#AgentRecharge_recharge_type').append('<option value=1>'+'$Credit'+'</option>');
		                //$('#AgentRecharge_recharge_type').append('<option value=2>'+'$Bank'+'</option>');
						$('#AgentRecharge_recharge_type').show();
						$('label:eq(2)').show();
						$('#AgentRecharge_recharge_type').change(function(){
							var rechargeType = $('#AgentRecharge_recharge_type option:selected').text();AgentRecharge_recharge_type
							if(rechargeType == '信用卡' || rechargeType == 'Credit Card'){
								if($cardInfoSize == 0){
									$('#prompt').show();
									$('#vista').show();
								}else{
									var num = $('.odd').length;
									if(num > 0){
										$('#card-info-grid').show();
									}else{
										$('#card-info-grid').hide();
									}	
								}
							}else{
								$('#card-info-grid').hide();
								$('#vista').hide();
								$('#prompt').hide();
							}
						})
				}else if(options=='$choose'){//选择,请选择,触发事件
		                $('#AgentRecharge_recharge_type').hide();
		                $('label:eq(2)').hide();
		                $('#card-info-grid').hide();
		                $('#vista').hide();
		                $('#prompt').hide();
		        }else if(options!='' && options!='1GB' && options!='$choose'){//选择,非请选择或非1GB套餐,触发事件
					$('#AgentRecharge_recharge_type').append('<option value=1>'+'$Credit'+'</option>');
		            //$('#AgentRecharge_recharge_type').append('<option value=2>'+'$Bank'+'</option>');
					$('#AgentRecharge_recharge_type').show();
					$('label:eq(2)').show();
					//这个地方加判断class = odd card-info-grid
					if($cardInfoSize == 0){
						$('#prompt').show();
						$('#vista').show();
					}else{
						var num = $('.odd').length;
						if(num > 0){
							$('#card-info-grid').show();
						}else{
							$('#card-info-grid').hide();
						}	
					}
				}
          }else{
                    $('#AgentRecharge_recharge_type').append('<option value=4>'+'$cash'+'</option>');
                    $('#AgentRecharge_recharge_type').append('<option value=2>'+'$transfer'+'</option>');
                    $('#AgentRecharge_recharge_type').show();
                    $('label:eq(2)').show();
                    
        }
	})
})");
?>
    
  <!-- 充值错误提示 -->
        <p class="red"> <?php
             if($_GET['fail_message'] == 1){
                 echo Yii::t('base', 'Note: payment charged fail.');
             }elseif($_GET['fail_message'] == 2){
                 echo Yii::t('base', 'Note: payment charged fail. No Credit Card information found.');
             }
             if($_GET['message'] == 1){
                 echo Yii::t('base', 'Please bind the bank card,in my account bind credit,then recharge.');
             }elseif($_GET['message'] == 2){
                 echo Yii::t('base', 'Please bind the credit card,then recharge.');
             }elseif($_GET['message'] == 3){
                 echo Yii::t('base', 'Sorry，you have already used the deposit payment once,please replace the other recharge mode.');
             }
        ?></p>
        
<script type="text/javascript">
	b = new Array();
	c= new Array();
	<?php 
		$sql2 = "select * from zy_package where package_type=1 and service_id =12";
		$connection = Yii::app()->db;
		$command = $connection->createCommand($sql2);
		$results2 = $command->queryAll();
		for($i=0;$i<count($results2);$i++){
	?>
	b[<?php echo $i;?>]= new Array("<?php echo $results2[$i]['package_id'];?>","<?php echo $results2[$i]['package_price'];?>");
	<?php } ?>
	//alert(b);
</script>
<?php
//level==8的情况 在线流量充值
$id=yii::app()->user->id;
$custom=Custom::model()->find('user_id='.$id);
$custom_id=$custom->custom_id;
?>
	<?php echo $form->errorSummary(array($model,$modelB)); ?>
	<div class="row">
		<?php 
		echo $form->hiddenField($model,'user_id',array('value'=>$id)); 
		?>
		<?php echo $form->error($model,'user_id'); ?>
	</div>

	<div class="row">
		<?php 
		echo $form->hiddenField($model,'agent_id',array('value'=>$custom_id)); 
	    ?>
		<?php echo $form->error($model,'agent_id'); ?>
	</div>
        <?php if($_GET['tag'] == 1){?>
        <div class="row">
		<?php echo $form->labelEx($model,'recharge_time'); ?>
		<input class="Wdate" type="text" name="AgentRecharge[recharge_time]" 
	 value="<?php echo $model->recharge_time=='0000-00-00 00:00:00'?date("Y-m-d H:i:s"):$model->recharge_time;?>" onClick="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})" />
		<?php echo $form->error($model,'recharge_time'); ?>
	</div>
        <?php }?>
	<div class="row">
		<?php echo $form->labelEx($model,'package_id');?>
		<?php //echo $form->dropDownList($model,'package_id',Package::model()->getRechargePackage()); 
			$sql="select * from zy_package where package_type = 1";
			$package=Yii::app()->db->createCommand($sql)->queryAll();	
		?>
		<select id="AgentRecharge_package_id" name="AgentRecharge[package_id]">
			<?php 
				for($i = 0; $i<count($package); $i++){
			?>
			<option value='<?php echo $package[$i]['package_id'];?>'><?php echo $package[$i]['package_name'].'---$'.$package[$i]['package_price']; ?></option>
			<?php } ?>
		</select>
		<?php echo $form->error($model,'package_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'recharge_number');?>
		<?php echo $form->dropDownList($model,'recharge_number',Package::model()->getRechargePackagePrice()); ?>
		<?php echo $form->error($model,'recharge_number'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'recharge_type')?>
		<?php echo $form->dropDownList($model,'recharge_type',array('3'=>Yii::t('base','Deduct from Deposit'),'1'=>Yii::t('base','Credit Card')/*,'2'=>'银行卡'*/)); ?>
		<?php  echo $form->error($model,'recharge_type'); ?>
	</div>
	<div id="prompt">
		<?php echo "<font color='red'>".Yii::t('base','Please fill out the bind credit card information, if you don\'t fill in, it defaults to using the old credit card payment!')."</font>";?>
	</div>
<div id="vista">
	<div class="row" >
		<?php echo $form->labelEx($modelB,'card_number'); ?>
		<?php echo $form->textField($modelB,'card_number',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($modelB,'card_number'); ?>
	</div>

	<div class="row" >
		<?php echo $form->labelEx($modelB,'name'); ?>
		<?php echo $form->textField($modelB,'name',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($modelB,'name'); ?>
	</div>
       
	<div class="row" >
		<?php echo $form->labelEx($modelB,'expirydate'); ?>
		<?php echo $form->textField($modelB,'expirydate',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($modelB,'expirydate'); ?>
	</div>
         <div class="row" id="two">
                <?php echo  Yii::t('base','Save for Future Recharge'); ?>
                <?php echo $form->checkBox($modelB,'defaultpay',array('value'=>1)); ?>
        </div>
</div>
<?php include dirname(__FILE__)."/../custom/credit_card_table.php";?>
        <!-- tag 起到后面充值及页面跳转控制作用 -->
        <input type="hidden" name="tag" id="tag" value="<?php echo $_GET['tag'];?>" />
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('base','Recharge') : Yii::t('base','Save')); ?>
	</div>
<?php $this->endWidget(); ?>

</div><!-- form -->
